const { getOnePackage, getData } = require('./dataFromWeb')
const { addCard, removeErrorPAndC, addSeriesAndPack } = require('./dataToSQL')

async function addCardIndex (series, pack, like) {
  let result = await addSeriesAndPack(series, pack, like)
  try {
    await getOnePackage(series, pack, addCard, result)
    return `系列${series},卡包 ${pack} 添加完成`
  } catch (error) {
    if (error.message === 'emptyPorS') {
      await removeErrorPAndC(result)
    }
    throw error
  }
}
module.exports = {
  addCardIndex
}